<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.bootcdn.net/ajax/libs/react/18.3.1/umd/react.development.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/18.3.1/umd/react-dom.development.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/babel-standalone/7.20.15/babel.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      let loading = true
      let age = 10
      // react函数就是一个组件，函数名就是组件名
      function HelloWorld({ name, age }) {
        let info = (
          <div>
            你好，{name},年龄：{age}
          </div>
        )

        if (name && age) {
          return info
        }

        return <div>你好，匿名用户,年龄：未知</div>
      }

      const appVnode = (
        <>
          <h3>{loading && <div>加载中....</div>}</h3>
          <h3>{age >= 18 ? '成年了' : ' 未成年'}</h3>
          <HelloWorld name="cqf" age="18" />
          <HelloWorld name="lm" age="19" />
          <HelloWorld />
        </>
      )

      // 将虚拟节点插入到dom树中
      ReactDOM.createRoot(document.getElementById('root')).render(appVnode)
    </script>
  </body>
</html>
